#include <functional>
#include <iostream>
#include <queue>
using namespace std;
#define int long long
 
signed main()
{
    int n = 0, x = 0, ret = 0;
    cin >> n;
    priority_queue<int ,vector<int>, greater<int>> heap;
    while(n--)
    {
        cin >> x;
        heap.push(x);
    }
    while(heap.size() != 1)
    {
        long long x1 = heap.top();
        heap.pop();
        long long x2 = heap.top();
        heap.pop();
 
        heap.push(x1 + x2);
        ret += x1 + x2;
    }
    cout << ret << endl;
    return 0;
}